package com.niyue.sandbox.invokevis.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class IvConfig {
	public final static String OUTPUT_FORMAT = "output.format";
	public final static String INVOKE_DEPTH = "invoke.depth";
	private static Properties configs = loadProperties("iv.properties");

	private static Properties loadProperties(String name, ClassLoader loader) {
		if (name == null)
			throw new IllegalArgumentException("null input: name");
		Properties result = null;

		InputStream in = null;
		try {
			if (loader == null)
				loader = ClassLoader.getSystemClassLoader();
			in = loader.getResourceAsStream(name);
			if (in != null) {
				result = new Properties();
				result.load(in); // Can throw IOException
			}
		} catch (IOException e) {
			result = null;
		} finally {
			if (in != null)
				try {
					in.close();
				} catch (Throwable e) {
					e.printStackTrace();
				}
		}
		return result;
	}

	private static Properties loadProperties(final String name) {
		return loadProperties(name, Thread.currentThread()
				.getContextClassLoader());
	}

	public static String getValue(String key) {
		return configs.getProperty(key);
	}

}
